package com.masterclient.app.modules.search.adapter;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.masterclient.app.R;
import com.masterclient.app.modules.search.SearchGoodBean;

import java.util.List;

/**
 * 作者：sean
 * 创建时间：2017/8/20 16:50
 * 功能说明：
 */

public class PromotionAdapter extends BaseAdapter{

    private List<SearchGoodBean.DataBean.ShPromotionsBean> list;
    private Context context;
    private String promotion_type = "";

    public PromotionAdapter(Context context) {
        this.context = context;
    }

    public void setList(List<SearchGoodBean.DataBean.ShPromotionsBean> list,String promotion_type) {
        this.list = list;
        this.promotion_type = promotion_type;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list == null?0:list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        SearchGoodBean.DataBean.ShPromotionsBean promotionBean = list.get(position);
        TextView tv = (TextView) View.inflate(context, R.layout.text_condition,null);
        tv.setText(promotionBean.getSh_name());
        if(!TextUtils.isEmpty(promotionBean.getSh_id())&&promotionBean.getSh_id().equals(promotion_type)){
            tv.setBackgroundResource(R.drawable.bg_rect_buy_black);
            tv.setTextColor(Color.parseColor("#ffffff"));
        }else {
            tv.setBackgroundResource(R.drawable.bg_rect_tag_black);
            tv.setTextColor(Color.parseColor("#333333"));
        }
        return tv;
    }
}
